From 5ba4a085e2a8f3cccfe9046f636a8dae25c970c2 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 12 May 2014 18:19:47 +0200 Subject: [PATCH] testsuite: Add a basic icontheme test Most of the work here is creating the infrastructure to have a custom icon theme to add icons to and run tests against. --- testsuite/gtk/Makefile.am | 7 +++ testsuite/gtk/icons/16x16/simple.png | Bin 0 -> 174 bytes testsuite/gtk/icons/index.theme | 12 ++++ testsuite/gtk/icontheme.c | 86 +++++++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 testsuite/gtk/icons/16x16/simple.png create mode 100644 testsuite/gtk/icons/index.theme create mode 100644 testsuite/gtk/icontheme.c diff --git a/testsuite/gtk/Makefile.am b/testsuite/gtk/Makefile.am index d5a1bcb479..9774a15846 100644 --- a/testsuite/gtk/Makefile.am +++ b/testsuite/gtk/Makefile.am @@ -40,6 +40,7 @@ TEST_PROGS += \ floating \ grid \ gtkmenu \ + icontheme \ keyhash \ listbox \ no-gtk-init \ @@ -124,10 +125,15 @@ keyhash_SOURCES = \ $(NULL) +test_icontheme = \ + icons/16x16/simple.png \ + icons/index.theme \ + $(NULL) EXTRA_DIST += \ file-chooser-test-dir/empty \ file-chooser-test-dir/text.txt \ + $(test_icontheme) \ $(NULL) GTK_GSETTINGS_SCHEMAS = \ @@ -149,6 +155,7 @@ all-am: gschemas.compiled if BUILDOPT_INSTALL_TESTS insttestdir = $(pkglibexecdir)/installed-tests insttest_PROGRAMS = $(TEST_PROGS) +insttest_DATA = $(test_icontheme) %.test: %$(EXEEXT) Makefile $(AM_V_GEN) (echo '[Test]' > $@.tmp; \ diff --git a/testsuite/gtk/icons/16x16/simple.png b/testsuite/gtk/icons/16x16/simple.png new file mode 100644 index 0000000000000000000000000000000000000000..91824f9750b4fd6cb608d2b35311740196bf2de0 GIT binary patch literal 174 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|oCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#9xD$o56jVO{|kXavY8S|xv6<2KrRD=b5UwyNotBhd1gt5g1e`0K#E=} zJ5XH3)5S4F<9u?;0mgs-|M!Q^>1=c{Sk)+TphJ6)q@<*~b7!3t!#qVcnOU3}i$Df> My85}Sb4q9e0P;I6QUCw| literal 0 HcmV?d00001 diff --git a/testsuite/gtk/icons/index.theme b/testsuite/gtk/icons/index.theme new file mode 100644 index 0000000000..79ecb1781b --- /dev/null +++ b/testsuite/gtk/icons/index.theme @@ -0,0 +1,12 @@ +[Icon Theme] +Name=Icons +Comment=Testing of the Icon theme code +Example=16x16/simple.png + +Directories=16x16 + +[16x16] +Context=16x16 icons +Size=16 +Type=Fixed + diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c new file mode 100644 index 0000000000..2f84616f83 --- /dev/null +++ b/testsuite/gtk/icontheme.c @@ -0,0 +1,86 @@ +#include + +#include + +static GtkIconTheme * +get_test_icontheme (void) +{ + static GtkIconTheme *icon_theme = NULL; + const char *current_dir; + + if (icon_theme) + return icon_theme; + + icon_theme = gtk_icon_theme_new (); + gtk_icon_theme_set_custom_theme (icon_theme, "icons"); + current_dir = g_get_current_dir (); + gtk_icon_theme_set_search_path (icon_theme, ¤t_dir, 1); + + return icon_theme; +} + +static char * +lookup_flags_to_string (GtkIconLookupFlags flags) +{ + GValue flags_value = { 0, }, string_value = { 0, }; + char *result; + + g_value_init (&flags_value, GTK_TYPE_ICON_LOOKUP_FLAGS); + g_value_init (&string_value, G_TYPE_STRING); + + g_value_set_flags (&flags_value, flags); + if (!g_value_transform (&flags_value, &string_value)) + { + g_assert_not_reached (); + } + + result = g_value_dup_string (&string_value); + + g_value_unset (&flags_value); + g_value_unset (&string_value); + + return result; +} + +static void +assert_icon_lookup (const char *icon_name, + gint size, + GtkIconLookupFlags flags, + const char *filename) +{ + GtkIconInfo *info; + + info = gtk_icon_theme_lookup_icon (get_test_icontheme (), icon_name, size, flags); + if (info == NULL) + { + g_error ("Could not look up an icon for \"%s\" with flags %s at size %d", + icon_name, lookup_flags_to_string (flags), size); + return; + } + + if (!g_str_has_suffix (gtk_icon_info_get_filename (info), filename)) + { + g_error ("Icon for \"%s\" with flags %s at size %d should be \"...%s\" but is \"...%s\"", + icon_name, lookup_flags_to_string (flags), size, + filename, gtk_icon_info_get_filename (info) + strlen (gtk_icon_info_get_filename (info)) - strlen (filename)); + return; + } + + g_object_unref (info); +} + +static void +test_basics (void) +{ + assert_icon_lookup ("simple", 16, 0, "/icons/16x16/simple.png"); +} + +int +main (int argc, char *argv[]) +{ + gtk_test_init (&argc, &argv); + + g_test_add_func ("/icontheme/basics", test_basics); + + return g_test_run(); +} -- 2.30.2